<%@ page import="java.util.Set" %>
<%@include file="/WEB-INF/pages/commons/commons.jsp"%>
<%@include file="/WEB-INF/pages/commons/nocache.jsp"%>

<jsecurity:lacksPermission name="user:viewUser:${actionBean.user.id}">
    No "user:viewUser:${actionBean.user.id}" permission
</jsecurity:lacksPermission>

<jsecurity:hasPermission name="user:viewUser:${actionBean.user.id}">
<script type="text/javascript">
    $(document).ready(function() {
        $("#close").click(function() {
            $("#space").fadeOut();
        })
    });
</script>

<stripes:form method="POST" action="">
        <h2>View user ${actionBean.user.username}</h2>
            <a id="close" href=""><fmt:message key="viewUserDetails.jsp.close"/></a>
        <br/>
        <table width="100%">
            <tr>
                <td><label><fmt:message key="viewUserDetails.jsp.id"/></label></td>
                <td><input type="text" name="id" value="${actionBean.user.id}" disabled="true" /></td>
            </tr>
            <tr>
                <td><label><fmt:message key="viewUserDetails.jsp.username"/></label></td>
                <td><input type="text" name="username" value="${actionBean.user.username}" disabled="true" /></td>
            </tr>
            <tr>
                <td><label><fmt:message key="viewUserDetails.jsp.email"/></label></td>
                <td><input type="text" name="email" value="${actionBean.user.email}" disabled="true"/></td>
            </tr>
            <tr>
                <td><label><fmt:message key="viewUserDetails.jsp.locked"/></label></td>
                <td><input type="checkbox" name="user.locked" value="${actionBean.user.locked}" disabled="true"/></td>
            </tr>
            <tr>
                <td><label><fmt:message key="viewUserDetails.jsp.disabled"/></label></td>
                <td><input type="checkbox" name="user.disabled" value="${actionBean.user.disabled}" disabled="true"/></td>
            </tr>
            <tr>
                <td><label><fmt:message key="viewUserDetails.jsp.expiryDate"/></label></td>
                <td><input type="checkbox" name="user.expiryDate" value="${actionBean.user.expiryDate}" disabled="true"/></td>
            </tr>
        </table>
            <h3><label><fmt:message key="viewUserDetails.jsp.roles"/></label></h3>
            <table width="100%">
                <thead>
                <tr>
                    <th><fmt:message key="viewUserDetails.jsp.rolesTable.roleNameColumn"/></th>
                    <th><fmt:message key="viewUserDetails.jsp.rolesTable.roleDescriptionColumn"/></th>
                </tr>
                </thead>
                <tbody>
                <c:set var="roles" value="${actionBean.user.roles}"/>
                <c_rt:set var="rolesSize" value='<%=((Set)pageContext.getAttribute("roles")).size()%>' />
                <c:choose>
                    <c:when test="${rolesSize gt 0}">
                        <c:forEach var="role" items="${roles}">
                            <c:set var="fmtRoleName" value="global.roles.name.${role.type}"/>
                            <c:set var="fmtRoleDescription" value="global.roles.description.${role.type}"/>
                            <tr>
                                <td>
                                    <fmt:message key="${fmtRoleName}" />
                                </td>
                                <td>
                                    <fmt:message key="${fmtRoleDescription}" />
                                </td>
                            </tr>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <tr><td colspan="2"><fmt:message key="global.roles.empty"/></td></tr>
                    </c:otherwise>
                </c:choose>
                </tbody>
            </table>
            <p/>
            <p/>

            <h3><label><fmt:message key="viewUserDetails.jsp.permissions"/></label></h3>
            <table width="100%">
                <thead>
                <tr>
                    <th><fmt:message key="viewUserDetails.jsp.permissionsTable.permissionNameColumn"/></th>
                    <th><fmt:message key="viewUserDetails.jsp.permissionsTable.permissionDescriptionColumn"/></th>
                </tr>
                </thead>
                <tbody>
                <c:set var="permissions" value="${actionBean.user.permissions}"/>
                <c_rt:set var="permissionsSize" value='<%=((Set)pageContext.getAttribute("permissions")).size()%>' />
                <c:choose>
                    <c:when test="${permissionsSize gt 0}">
                        <c:forEach var="permission" items="${permissions}">
                            <c:set var="fmtPermissionName" value="global.permissions.name.${permission.type}"/>
                            <c:set var="fmtPermissionDescription" value="global.permissions.description.${permission.type}"/>
                            <tr>
                                <td>
                                    <fmt:message key="${fmtPermissionName}" />
                                </td>
                                <td>
                                    <fmt:message key="${fmtPermissionDescription}" />
                                </td>
                            </tr>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <tr><td colspan="3"><fmt:message key="global.permissions.empty"/></td></tr>
                    </c:otherwise>
                </c:choose>
                </tbody>
            </table>
        </p>
        <p/>
        <p/>
</stripes:form>
</jsecurity:hasPermission>
